package com.maozzi.service.logger.business;

import com.maozzi.api.logger.LogService;
import com.maozzi.api.logger.model.LoggerDTO;
import com.maozzi.common.enums.BizCodeEnum;
import com.maozzi.common.exception.BizException;
import com.maozzi.common.util.CloneUtil;
import com.maozzi.service.logger.domain.LogDomainService;
import com.maozzi.service.logger.repository.model.Log;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 用户
 *
 * @author maozi
 */
@Service
public class LogServiceImpl implements LogService {

    @Resource
    private LogDomainService logDomainService;

    @Override
    public void addLog(LoggerDTO loggerDTO) throws BizException {
        Log log = CloneUtil.to(loggerDTO, Log.class);

        Log putLog = logDomainService.addLog(log);
        if (ObjectUtils.isEmpty(putLog)) {
            throw new BizException(BizCodeEnum.FAILED_OPERATION, "保存日志失败");
        }
    }
}
